package com.goddess.yeecolor.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;

import com.goddess.yeecolor.R;
import com.goddess.yeecolor.adapter.ExerciseFragmentPagerAdapter;
import com.goddess.yeecolor.base.BaseActivity;
import com.goddess.yeecolor.fragment.MyHuoDongAllFragment;
import com.goddess.yeecolor.tools.JumpIntents;

import java.util.ArrayList;
import java.util.List;

/**
 *我的活动
 */
public class MyHuoDongAcitivity extends BaseActivity{

    private ExerciseFragmentPagerAdapter adapter;
    private MyHuoDongAllFragment all,finish,obligationFragment,partakeFragment;
    private List<String> mTitles;
    private List<Fragment>mListFragment;
    private Toolbar mToolbar;
    private TextView  mTitle;
    private TabLayout mTablayout;
    private ViewPager mViewPager;
    private View mView;
    private String tag;
    private int position;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        setTheme(R.style.AppTheme);
        super.onCreate(savedInstanceState);

            mView= LayoutInflater.from(this).inflate(R.layout.activity_huodong,null);

            setContentView(mView);
            tag=getIntent().getBundleExtra("bundle").getString("Tags");

            initFindView();

    }



    @Override
    public void initOnClck() {

    }

    @Override
    public void initFindView() {
        mToolbar= (Toolbar) findViewById(R.id.title_toobar);
        mTablayout= (TabLayout) mView.findViewById(R.id.donghua_tablayout);
        mViewPager= (ViewPager) mView.findViewById(R.id.donghua_viewpager);
        mTitle= (TextView) mView.findViewById(R.id.title_content);
        mTitle.setText("活动详情");

        mToolbar.setTitleTextColor(getResources().getColor(R.color.purple));
//        setSupportActionBar(mToolbar);
//        getSupportActionBar().setDisplayShowTitleEnabled(false);

        // 左上的图标按钮
        mToolbar.setNavigationIcon(R.mipmap.back3x);
        // 左上的图标按钮点击事件


        setTabLayout();
        mToolbar.setNavigationOnClickListener(view -> {
            setFiish(this);
        });
    }

    @Override
    public void initData() {

    }

    /**
     * 设置tablayout
     */
    private Fragment fragment;
    private void setTabLayout(){
        mListFragment=new ArrayList<>();
        all= MyHuoDongAllFragment.newInstance(1);
        obligationFragment=MyHuoDongAllFragment.newInstance(2);
        partakeFragment=MyHuoDongAllFragment.newInstance(3);
        finish= MyHuoDongAllFragment.newInstance(4);
        mListFragment.add(all);
        mListFragment.add(obligationFragment);
        mListFragment.add(partakeFragment);
        mListFragment.add(finish);
        mTitles=new ArrayList<>();

        mTitles.add("全部");
        mTitles.add("待付款");
        mTitles.add("待参与");
        mTitles.add("已完成");
        mTablayout.addTab(mTablayout.newTab().setText("全部"),true);
        mTablayout.addTab(mTablayout.newTab().setText("待付款"),false);
        mTablayout.addTab(mTablayout.newTab().setText("待参与"),true);
        mTablayout.addTab(mTablayout.newTab().setText("已完成"),false);
        mTablayout.setTabMode(TabLayout.MODE_FIXED);
        adapter=new ExerciseFragmentPagerAdapter(getSupportFragmentManager(),mListFragment,mTitles);
        mViewPager.setAdapter(adapter);

        mTablayout.setupWithViewPager(mViewPager);

        if (tag.equals("待付款")){
            mTablayout.getTabAt(1).select();//默认选中

        }
        else if (tag.equals("待参与")){
            mTablayout.getTabAt(2).select();//默认选中

        }
        else if (tag.equals("已完成")){
            mTablayout.getTabAt(3).select();//默认选中

        }
        else {
            mTablayout.getTabAt(0).select();//默认选中
        }
//        mTablayout.getTabAt(0).select();//默认选中





    }
        @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater menuInflater = getMenuInflater();
        menuInflater.inflate(R.menu.toolbar_menu, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {

        switch (item.getItemId()){
            case R.id.menu_right:
                JumpIntents.startIntent(this,NewsActivity.class);
                break;
        }
        return super.onOptionsItemSelected(item);
    }





}
